package router

import (
	"goapp-web-server/app/controller"
	"goapp-web-server/app/service"

	"github.com/kataras/iris"
	"github.com/kataras/iris/mvc"
)

func Configurator(app *iris.Application) {
	// route func
	route := func(path string, controller interface{}, service interface{}) {
		mvc.Configure(app.Party(path), func(app *mvc.Application) {
			// Register service
			app.Register(service)
			// Hander controller
			app.Handle(controller)
		})
	}

	// Method:   GET
	app.Handle("GET", "/", func(ctx iris.Context) {
		ctx.HTML("<h1>Welcome</h1>")
	})

	// category
	route("/api/category", new(controller.CmsCategoryController), service.NewCategoryService())
	// article
	route("/api/article", new(controller.CmsArticleController), service.NewArticleService())
	// comment
	route("/api/comment", new(controller.CmsCommentController), service.NewCommentService())
	// comment
	route("/api/material", new(controller.CmsMaterialController), service.NewMaterialService())
	// sys user
	route("/api/user", new(controller.SysUserController), service.NewUserService())
	// sys role
	route("/api/role", new(controller.SysRoleController), service.NewRoleService())
	// sys menu
	route("/api/menu", new(controller.SysMenuController), service.NewMenuService())
}
